function addWithPrecision (a, b, precision) {
  const factor = Math.pow(10, precision);
  return Math.round((a + b) * factor) / factor;
}

// 示例用法：
const result = addWithPrecision(0.1, 0.2, 10);
console.log(result); // 输出: 0.3